package com.yunzhou.action;

import com.yunzhou.common.DataChangeService;
import com.yunzhou.common.DataChangeServiceImpl;
import com.yunzhou.u8.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;

import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCode;

public class updateProjectAction extends AbstractModeExpandJavaCode {
    /**
     * 执行模块扩展动作
     *
     * @param param param包含(但不限于)以下数据
     * user 当前用户
     */
    private Log log = LogFactory.getLog(updateProjectAction.class.getName());

    public void doModeExpand(Map<String, Object> param) throws Exception {

        log.info("updateProjectAction进来了");

        User user = (User) param.get("user");
        int billid = -1;//数据id
        int modeid = -1;//模块id
        RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");

        String xmmc = "";//项目名称
        String xmfl = "";//项目分类
        String xmbm = "";//项目编码
        String ssgs = "";//所属公司

        if (requestInfo != null) {
            billid = Util.getIntValue(requestInfo.getRequestid());
            modeid = Util.getIntValue(requestInfo.getWorkflowid());
            if (billid > 0 && modeid > 0) {
                String sql = "select * from uf_xmhdb where id = " + billid;
                log.info("sql---sql:" + sql);
                RecordSet rs = new RecordSet();
                rs.execute(sql);
                if (rs.next()) {
                    xmmc = rs.getString("xmmc");
                    xmfl = rs.getString("xmfl");
                    xmbm = rs.getString("xmbm");
                    ssgs = rs.getString("ssgs");
                }
                log.info("值分别是，xmmc：" + xmmc + "，xmfl：" + xmfl + "，xmbm：" + xmbm + "，ssgs：" + ssgs);

                //值转换
                DataChangeService dataChangeService = new DataChangeServiceImpl();
                HashMap mapGs = dataChangeService.getSpecifiedTableMap("hrmsubcompany", "id", "subcompanydesc");//分部集合
                ssgs = mapGs.get(ssgs).toString();
                log.info("转换后公司 : " + ssgs);

                String result = "";
                try {
                    ServiceForOA workflowServiceXmlLocator = new ServiceForOALocator();//U8接口
                    result = workflowServiceXmlLocator.getserviceForOASoap().updateItem(ssgs, xmbm, xmmc, xmfl);//citemname（项目名称），cItemCcode（项目分类）
                    log.info("billid:" + billid + "更新项目成功，返回了结果====" + result);
                } catch (Exception ex) {
                    log.info("billid:" + billid + "更新项目失败，返回了错误====" + result);
                    ex.printStackTrace();
                }

            }
        }
    }

}